package controller

import (
	"gin/common/lib"
	"gin/middleware"
	"gin/service/base"
	"gin/util/jwt"
	"gin/util/map_builder"
	"gin/util/tool"

	"github.com/gin-gonic/gin"
)

type HomeController struct {
}

func HomeRegister(router lib.RegisterRouterGroup, needLoginRouter lib.RegisterRouterGroup) {
	c := HomeController{}
	needLoginRouter.POST("/home/releasePic", c.releasePic)
	needLoginRouter.POST("/home/uploadPic", c.uploadPic)
}

// @Summary 上传图片
func (*HomeController) releasePic(c *gin.Context) {
	uid := jwt.GetUid(c, true)
	upInfo := tool.UpdPicFile(c, "base", 1024*1024*20, false)

	base.Add(uid, upInfo.Path)
	middleware.Success(c, map_builder.BuilderMap("url", upInfo.Path, "preview", upInfo.Full))
}

func (*HomeController) uploadPic(c *gin.Context) {
	uid := jwt.GetUid(c, true)
	upInfo := tool.UpdAllFile(c, "base", 1024*1024*20)

	base.Add(uid, upInfo.Path)
	middleware.Success(c, map_builder.BuilderMap("url", upInfo.Path, "preview", upInfo.Full))
}
